import React from 'react'
import { Button } from 'antd'
import { TranslationOutlined } from '@ant-design/icons'
import {translateText} from '@/apis/tools'
interface TranslateBtnProps {
  value: string
  to?: string
  from?: string
  onChange?: (val: string) => void
}
const TranslateBtn = ({value, to, from, onChange}: TranslateBtnProps) => {
  return (
    <Button onClick={async()=>{
      const res = await translateText(value, to, from)
      if(res?.code === 0){
        onChange?.(res?.data?.tgt_text)
      }
    }} size='small' type='link'><TranslationOutlined />翻译</Button>
  )
}

export default TranslateBtn